#ifndef QOPENHARMONYCAMERASESSION_H
#define QOPENHARMONYCAMERASESSION_H

#include <QObject>
#include <qcamera.h>

#include "openharmonycamera.h"

QT_BEGIN_NAMESPACE

class QOPenHarmonyCameraSession : public QObject
{
    Q_OBJECT
public:
    explicit QOPenHarmonyCameraSession(QObject *parent = nullptr);
    ~QOPenHarmonyCameraSession();
    static const QList<OPenHarmonyCameraInfo> &availableCameras();

    QCamera::State state() const { return m_state; }
    void setState(QCamera::State state);

    QCamera::Status status() const { return m_status; }

    QCamera::CaptureModes captureMode() const { return m_captureMode; }
    void setCaptureMode(QCamera::CaptureModes mode);
    bool isCaptureModeSupported(QCamera::CaptureModes mode) const;

Q_SIGNALS:
    void statusChanged(QCamera::Status status);
    void stateChanged(QCamera::State);
    void error(int error, const QString &errorString);
    void captureModeChanged(QCamera::CaptureModes);

private Q_SLOTS:
    void onApplicationStateChanged(Qt::ApplicationState state);

private:
    static void updateAvailableCameras();
    bool open();
    void close();

    bool startPreview();
    void stopPreview();

    void setStateHelper(QCamera::State state);

    OPenHarmonyCamera *m_camera;
    QCamera::State m_state;
    int m_savedState;
    QCamera::Status m_status;
    QCamera::CaptureModes m_captureMode;
};

QT_END_NAMESPACE
#endif // QOPENHARMONYCAMERASESSION_H
